package com.dao;

import com.bean.Orders;
import com.util.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class GenerateOrder {
    //1.准备连接对象
    Connection conn;
    //2.准备编译对象
    PreparedStatement ps;
    public boolean insertOrder(int UserID,int ProductID,int Quantity,Double TotalPrice,String idLast) {
        boolean b = false;
        //3.开始连接数据库
        conn = BaseDao.getConn();
        //4.准备SQL语句
        String sql = "exec GenerateOrder @UserID = ?, @ProductID = ?, @Quantity = ?, @TotalPrice = ?,@idLast = ?";
        //5.编译SQL语句
        try {
            ps = conn.prepareStatement(sql);
            //6.设置？的值
            ps.setInt(1,UserID);
            ps.setInt(2,ProductID);
            ps.setInt(3,Quantity);
            ps.setDouble(4,TotalPrice);
            ps.setString(5,idLast);
            //7.执行SQL语句
            int a = ps.executeUpdate();
            if(a>0){
                b = true;
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return b;
    }
}
